/*
 * The core file for my botbase, once again i am useing brodie's compendium as a refference
 * I am also useing the Combat Bot shippped with HB as a refference.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;

using Bots;
using Bots.DungeonBuddy;
using Bots.DungeonBuddy.Helpers;
using Styx.Common;
using Styx.CommonBot;
using Styx.TreeSharp;


namespace OCBotBase
{
    public class OCBot : BotBase
    {
        private Ocnathor_Bot_Updater BotUpdater;
        private oc_DataStore questData;

        string DataFile = "CollectionOrganizer.xml";

        public bool hasBeenInitialized = false;

        #region Overrides
        public string Author { get { return "Ocnathor"; } }
        public Version Version { get { return new Version(0, 1, 0); } }

        public override string Name
        {
            get { return "OC Bot"; }
        }
        private Composite _root;
        public override Styx.TreeSharp.Composite Root
        {
            get { return _root; }
        }
        public override PulseFlags PulseFlags
        {
            get { return PulseFlags.All & ~(PulseFlags.Looting | PulseFlags.CharacterManager); }
        }
        #endregion

        public override void Initialize()
        {
            //base.Initialize();
            if (!hasBeenInitialized)
            {
                Logging.Write("Loaded OCBot Version: " + Version.ToString());
                Logging.Write("Please Wait while [OCBot] checks for updates, this may take a few minutes");
                hasBeenInitialized = true;
                try
                {
                    BotUpdater = new Ocnathor_Bot_Updater("http://oc-botbase.googlecode.com/svn/trunk/", "oc-botbase");
                    if (BotUpdater.UpdateAvailable())
                    {
                        Logging.Write("[OCBot] Update to r" + BotUpdater.GetNewestRev().ToString() + " Avaliable. Currently on r" + BotUpdater.GetCurrentRev().ToString());
                        Logging.Write("[OCBOT] Starting Update");
                        if (BotUpdater.Update())
                        {
                            Logging.Write("[OCBOT] Update Successful, Please restart honorbuddy");
                        }
                        else
                        {
                            Logging.Write("[OCBOT] Error updating");
                        }
                    }
                    else
                    {
                        Logging.Write("[OCBot] Is at r" + BotUpdater.GetNewestRev().ToString() + " And up to date");
                    }
                }
                catch(Exception ex)
                {
                    Logging.Write("Unable to run [OCBot] update process");
                    Logging.Write(LogLevel.Diagnostic, "[OCBot]: Exception " + ex.Message);
                }

                try
                {
                    questData = new oc_DataStore(DataFile);
                }
                catch (Exception ex)
                {
                    Logging.Write("Unable to run [OCBot] Data Load");
                    Logging.Write(LogLevel.Diagnostic, "[OCBot]: Exception " + ex.Message);
                }
            }
        }

        public override void Pulse()
        {
            //base.Pulse();
            
        }

        public override void Start()
        {
            base.Start();
            Logging.Write("[OCBot] Starting");
            Logging.Write("Map ID: {0}. Name {1}. AreaID {2}", Styx.StyxWoW.Me.MapId, Styx.StyxWoW.Me.MapName, Styx.StyxWoW.Me.AreaId);
            Logging.Write("Zone ID: {0}. Name {1}.", Styx.StyxWoW.Me.ZoneId, Styx.StyxWoW.Me.ZoneText);
            
            

            
        }

        public override void Stop()
        {
            base.Stop();
            Logging.Write("[OCBot] Stopping");
        }
    }
}